<!--
//******************************************************************/
//Modification History
//******************************************************************/
//CR log no 1054: By Oscar Bai  Date:2003/02
//CR log no 1266: By Ploy Li on 2004-04-27
//CR log no 1764: By Shu Sun Lee Date: 26/07/2007
//******************************************************************/
-->

<%@ page import="com.ffpc.struts.StrutsMessage" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.net.URLDecoder" %>
<%--<%@ page import="ccs.options.*" %>--%>
<%@ page import="admin.*" %>
<%@ page import="com.ffpc.sql.*"%>

<%
    ConnectionFactory connectionFactory = null;
    Connection con = null;
    StrutsMessage message = (StrutsMessage)request.getAttribute("message");
    if (message==null)
       message = new StrutsMessage();
    String contextPath = request.getContextPath();
    String cssPath = contextPath + "/style";
    String jsPath = contextPath + "/scrip";
    String resPath = contextPath + "/resource";
    
    String formAction = request.getParameter("formAction");
    String readOnly = new String("");
    if (formAction!=null && formAction.trim().equalsIgnoreCase("Update"))
       readOnly = new String(" readonly ");
    User user = (User)session.getAttribute("user");
    String sid = "";
    try{
    connectionFactory = new ConnectionFactory();
    con = (Connection)connectionFactory.getConnection();
    request.setAttribute("jis.con", con); //see ConnectionCleanupFilter
    
    sid = connectionFactory.getSID();
    if (sid=="csms") {sid="prod";}
    }finally
    {
    	//connectionFactory.finalize(); //CR log no 1266
    }
%>

<LINK rel='stylesheet' type='text/css' href='<%=contextPath%>/style.css'>
<head>
   <title>Hutchison - FAS Application</title>
</head>
<table width=100% cellpadding=0 cellspacing=0>
<tr>
<td align=left style="color:white;background-color:#00AADD;" > * - Mandatory Field</td>
<td align=right style="color:white;background-color:#00AADD;" >Welcome &nbsp; &nbsp;<b><i><%=user.getUser_name()%> - <%=user.getCost_center_id()%></i></b></td>
</tr>
</table>
<% if (message.getMessage()!=null && message.getMessage().trim().length()>3 )
   { %>
  <script lang=javascript >
          alert('<%= message.getMessage() %>');
  </script>
<%
  //CR log no 1054 begin of: Don't show message dialog when the page back;

  message.setMessage("");

  //CR log no 1054 end of;
  }
%>

<script language=javascript>

 function Tokenizer(string, separator, pos)
 {
    var oText = string;
    var nText = null;
    for (var i=0; i < pos; i++)
    {
       if (oText.indexOf(separator)==-1)
       {
          nText = oText
       }
       else
       {
          nText = oText.substring(0, oText.indexOf(separator));
          oText = oText.substring(oText.indexOf(separator)+1);
       }
    }
    return nText;
 }

 function isNull(object,desc) {
          var obj=object;
          if (obj.value==null||obj.value.length==0) {
             alert(desc + " cannot be null! ");
             return true;
          }
          return false;
 }

 function isInt(object) {
    var obj=object;
    if (parseInt(obj.value)==parseFloat(obj.value)) {
      return true;
    }
      return false;
 }

 function isNotNumeric(object,desc) {
          var obj=object;

          if (obj.value!=null && isNaN(obj.value)) {
             alert(desc + "  must be numeric!");
             return true;
          }
          return false;
 }

// CR1054 This is a more comprehensive function for date validation
// and can be used to replace isDate() below

 function validationDate(dateStr) {

    var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
    var matchArray = dateStr.match(datePat);

    if (matchArray == null) {
        return false;
    }

    day = matchArray[1];
    month = matchArray[3];
    year = matchArray[5];

    if (day < 1 || day > 31) {
        return false;
    }

    if (month < 1 || month > 12) {
        return false;
    }

    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        return false;
    }

    if (month == 2) {
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {
            return false;
        }
    }
    return true;
}

 function isDate(object,desc) {
          var obj=object;
          var d = obj.value;
          if (chLen(obj," date field (dd/MM/yyyy) ",10)==false)
             return false;
          if (d.substring(2,3)!="/" || d.substring(5,6)!="/") {
             alert(" Invalid Date Format.");
             return false;
          }
          var day = d.substring(0,2);
          var month = d.substring(3,5);
          var year = d.substring(6,10);
          if (day==null || isNaN(day)) {
             alert(" Invalid Date Format.");
             return false;
          }
          if (month==null || isNaN(month)) {
             alert(" Invalid Date Format.");
             return false;
          }
          if (day==null || isNaN(day)) {
             alert(" Invalid Date Format.");
             return false;
          }
          if (parseInt(day)>31) {
             alert(" Invalid Date Format.");
             return false;
          }
          if (parseInt(month)>12) {
             alert(" Invalid Date Format.");
             return false;
          }
          return true;
 }


 function chLen(object,desc,len) {
          var obj=object;

          if (obj.value!=null && obj.value.length!=len) {
             alert("The field length of " + desc + "  must be " + len + "! ");
             return false;
          }
          return true;
 }

 function deleteRecord() {
          if (fm.formAction.value!="Update")
          {
                alert('This is a new record.');
                return;
          }
          if (confirm("Are you sure to delete this record?"))
          {

             fm.formAction.value="Delete";
             fm.submit();
          }
 }

 function save() {
          if (confirm("Are you sure to save this record ?"))
          {
             if (!formValidation())
                return false;
             fm.submit();
          }
 }
 function saveWithoutConfirm() {
          
//          alert('saveWithoutConfirm!');
          
             if (!formValidation()){
                return false;
             }
             fm.submit();
//          alert('saveWithoutConfirm after submit!');
 }
 function search() {
             if (!formValidation())
                return;
             fm.submit();
 }

 function spsubmit() {
          if (confirm("Are you sure to submit this request ?"))
          {
             if (!formValidation())
                return;
             fm.submit();
          }
 }

 function addNewRow(targetTable,newRowTemplate){
    var newRow = targetTable.insertRow();
    for(var i=0; i<newRowTemplate.rows(0).cells.length; i++){
      newRow.insertCell().innerHTML = newRowTemplate.rows(0).cells(i).innerHTML;
    }
    return newRow;
 }

 function delRows(targetTable,startRow,checkCellIndex,checkChildIndex,statusCellIndex,statusChildIndex,statusForDelete,deleteStatus) {
  if (confirm("Are you to delete this record ?")) {
    var checkCell   = checkCellIndex;
    var checkChild  = checkChildIndex;
    var statusCell  = statusCellIndex;
    var statusChild = statusChildIndex;
    for (var i=startRow; i<targetTable.rows.length; i++ ) {
      if (targetTable.rows(i).cells(checkCell).children(checkChild).checked) {
         if (targetTable.rows(i).cells(statusCell).children(statusChild).value!=statusForDelete) {
            targetTable.deleteRow(i);
            i = i - 1;
         } else {
           targetTable.rows(i).style.display = 'none';
           targetTable.rows(i).cells(statusCell).children(statusChild).value = deleteStatus;
         }
      }
    }
  }
 }

 function delAllRows(targetTable) {
    for (var i=0; i<targetTable.rows.length; i++ ) {
        targetTable.deleteRow(i);
        i = i - 1;
    }
 }

 function delRow(targetTable,rownum) {
    targetTable.deleteRow(rownum);
 }

 function encode(s) {
    t="";
    for (var i=0;i<s.length;++i) {
        ch=s.charAt(i);
        if (ch=="/") t +="//"
        else if (ch==" ") t += "/b"
        else if (ch==",") t += "/."
        else if (ch==";") t += "/:"
        else if (ch=="\n") t += "/n"
        else if (ch=="\r") t += "/r"
        else if (ch=="\t") t += "/t"
        else if (ch=="\b") t += "/b"
        else t += ch;
    }
    return t;
 }

 function decode(s) {
    t="";
    if (s==null) return;
    for (var i=0;i<s.length;++i) {
        ch=s.charAt(i);
        if (ch=="/") {
           ++i;
           if (i<s.length) {
              ch=s.charAt(i);
              if (ch=="/") t += ch
              else if (ch==".") t += ","
              else if (ch==":") t += ";"
              else if (ch=="n") t += "\n"
              else if (ch=="r") t += "\r"
              else if (ch=="t") t += "\t"
              else if (ch=="b") t += " "
           }
        } else t += ch
    }
    return t;
 }

var EARLIER = -1
var SAME = 0
var LATER = 1

function convertDate(dateString) {
	var iDay = parseInt(dateString.substr(0, 2), 10)
	var iMonth = parseInt(dateString.substr(3, 2), 10) - 1
	var iYear = parseInt(dateString.substr(6, 4), 10)

	return(new Date(iYear, iMonth, iDay))
}

function compareDate(date1, date2) {

	if (date1-date2 < 0)
		return EARLIER
	else if(date1-date2 > 0)
		return LATER
	else
		return SAME
}


</script>

